package com.exchange.until;

import lombok.Data;

import java.io.Serializable;

/**
 * @Author : RulerWood
 * @Data : 2024/4/26 - 16:31
 */
@Data
public class Result <T> implements Serializable {
    private Integer code;
    private String message;
    private boolean success;
    private T result;

    public static <T> Result<T> success(T result) {
        return new Result(200, "成功", true, result);
    }

    public static <T> Result<T> success() {
        return new Result(200, "成功", true);
    }

    public static <T> Result<T> error(T result) {
        return new Result(400, "请求失败", true, result);
    }

    public static <T> Result<T> error() {
        return new Result(400, "请求失败", true);
    }

    public Result() {
    }

    public Result(Integer code, String message, boolean flag) {
        this.code = code;
        this.message = message;
        this.success = flag;
    }

    public Result(Integer code, String message, boolean flag, T result) {
        this.code = code;
        this.message = message;
        this.success = flag;
        this.result = result;
    }

    public static Result error(String message) {
        return new Result(500, message, false);
    }
    public static Result success(String message) {
        return new Result(200, message, true);
    }
}
